home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / ntpath.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  11KB  |  412 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Common pathname manipulations, WindowsNT/95 version.
  5.  
  6. Instead of importing this module directly, import os and refer to this
  7. module as os.path.
  8. '''
  9. import os
  10. import sys
  11. import stat
  12. import genericpath
  13. import warnings
  14. from genericpath import *
  15. __all__ = [
  16.     'normcase',
  17.     'isabs',
  18.     'join',
  19.     'splitdrive',
  20.     'split',
  21.     'splitext',
  22.     'basename',
  23.     'dirname',
  24.     'commonprefix',
  25.     'getsize',
  26.     'getmtime',
  27.     'getatime',
  28.     'getctime',
  29.     'islink',
  30.     'exists',
  31.     'lexists',
  32.     'isdir',
  33.     'isfile',
  34.     'ismount',
  35.     'walk',
  36.     'expanduser',
  37.     'expandvars',
  38.     'normpath',
  39.     'abspath',
  40.     'splitunc',
  41.     'curdir',
  42.     'pardir',
  43.     'sep',
  44.     'pathsep',
  45.     'defpath',
  46.     'altsep',
  47.     'extsep',
  48.     'devnull',
  49.     'realpath',
  50.     'supports_unicode_filenames',
  51.     'relpath']
  52. curdir = '.'
  53. pardir = '..'
  54. extsep = '.'
  55. sep = '\\'
  56. pathsep = ';'
  57. altsep = '/'
  58. defpath = '.;C:\\bin'
  59. if 'ce' in sys.builtin_module_names:
  60.     defpath = '\\Windows'
  61. elif 'os2' in sys.builtin_module_names:
  62.     altsep = '/'
  63.  
  64. devnull = 'nul'
  65.  
  66. def normcase(s):
  67.     '''Normalize case of pathname.
  68.  
  69.     Makes all characters lowercase and all slashes into backslashes.'''
  70.     return s.replace('/', '\\').lower()
  71.  
  72.  
  73. def isabs(s):
  74.     '''Test whether a path is absolute'''
  75.     s = splitdrive(s)[1]
  76.     if s != '':
  77.         pass
  78.     return s[:1] in '/\\'
  79.  
  80.  
  81. def join(a, *p):
  82.     '''Join two or more pathname components, inserting "\\" as needed.
  83.     If any component is an absolute path, all previous path components
  84.     will be discarded.'''
  85.     path = a
  86.     for b in p:
  87.         b_wins = 0
  88.         if path == '':
  89.             b_wins = 1
  90.         elif isabs(b):
  91.             if path[1:2] != ':' or b[1:2] == ':':
  92.                 b_wins = 1
  93.             elif (len(path) > 3 or len(path) == 3) and path[-1] not in '/\\':
  94.                 b_wins = 1
  95.             
  96.         
  97.         if b_wins:
  98.             path = b
  99.             continue
  100.         len(path) > 0 if not len(path) > 0 else b[0] in '/\\'
  101.         None if path[-1] == ':' else b[0] in '/\\'
  102.         path += '\\'
  103.     
  104.     return path
  105.  
  106.  
  107. def splitdrive(p):
  108.     '''Split a pathname into drive and path specifiers. Returns a 2-tuple
  109. "(drive,path)";  either part may be empty'''
  110.     if p[1:2] == ':':
  111.         return (p[0:2], p[2:])
  112.     return ('', p)
  113.  
  114.  
  115. def splitunc(p):
  116.     """Split a pathname into UNC mount point and relative path specifiers.
  117.  
  118.     Return a 2-tuple (unc, rest); either part may be empty.
  119.     If unc is not empty, it has the form '//host/mount' (or similar
  120.     using backslashes).  unc+rest is always the input path.
  121.     Paths containing drive letters never have an UNC part.
  122.     """
  123.     if p[1:2] == ':':
  124.         return ('', p)
  125.     firstTwo = p[0:2]
  126.     if firstTwo == '//' or firstTwo == '\\\\':
  127.         normp = normcase(p)
  128.         index = normp.find('\\', 2)
  129.         if index == -1:
  130.             return ('', p)
  131.         index = normp.find('\\', index + 1)
  132.         return (p[:index], p[index:])
  133.     return ('', p)
  134.  
  135.  
  136. def split(p):
  137.     '''Split a pathname.
  138.  
  139.     Return tuple (head, tail) where tail is everything after the final slash.
  140.     Either part may be empty.'''
  141.     (d, p) = splitdrive(p)
  142.     i = len(p)
  143.     while i and p[i - 1] not in '/\\':
  144.         i = i - 1
  145.     head = p[:i]
  146.     tail = p[i:]
  147.     head2 = head
  148.     while head2 and head2[-1] in '/\\':
  149.         head2 = head2[:-1]
  150.     if not head2:
  151.         pass
  152.     head = head
  153.     return (d + head, tail)
  154.  
  155.  
  156. def splitext(p):
  157.     return genericpath._splitext(p, sep, altsep, extsep)
  158.  
  159. splitext.__doc__ = genericpath._splitext.__doc__
  160.  
  161. def basename(p):
  162.     '''Returns the final component of a pathname'''
  163.     return split(p)[1]
  164.  
  165.  
  166. def dirname(p):
  167.     '''Returns the directory component of a pathname'''
  168.     return split(p)[0]
  169.  
  170.  
  171. def islink(path):
  172.     '''Test for symbolic link.
  173.     On WindowsNT/95 and OS/2 always returns false
  174.     '''
  175.     return False
  176.  
  177. lexists = exists
  178.  
  179. def ismount(path):
  180.     '''Test whether a path is a mount point (defined as root of drive)'''
  181.     (unc, rest) = splitunc(path)
  182.     if unc:
  183.         return rest in ('', '/', '\\')
  184.     p = splitdrive(path)[1]
  185.     if len(p) == 1:
  186.         pass
  187.     return p[0] in '/\\'
  188.  
  189.  
  190. def walk(top, func, arg):
  191.     """Directory tree walk with callback function.
  192.  
  193.     For each directory in the directory tree rooted at top (including top
  194.     itself, but excluding '.' and '..'), call func(arg, dirname, fnames).
  195.     dirname is the name of the directory, and fnames a list of the names of
  196.     the files and subdirectories in dirname (excluding '.' and '..').  func
  197.     may modify the fnames list in-place (e.g. via del or slice assignment),
  198.     and walk will only recurse into the subdirectories whose names remain in
  199.     fnames; this can be used to implement a filter, or to impose a specific
  200.     order of visiting.  No semantics are defined for, or required of, arg,
  201.     beyond that arg is always passed to func.  It can be used, e.g., to pass
  202.     a filename pattern, or a mutable object designed to accumulate
  203.     statistics.  Passing None for arg is common."""
  204.     warnings.warnpy3k('In 3.x, os.path.walk is removed in favor of os.walk.', stacklevel = 2)
  205.     
  206.     try:
  207.         names = os.listdir(top)
  208.     except os.error:
  209.         return None
  210.  
  211.     func(arg, top, names)
  212.     for name in names:
  213.         name = join(top, name)
  214.         if isdir(name):
  215.             walk(name, func, arg)
  216.             continue
  217.     
  218.  
  219.  
  220. def expanduser(path):
  221.     '''Expand ~ and ~user constructs.
  222.  
  223.     If user or $HOME is unknown, do nothing.'''
  224.     if path[:1] != '~':
  225.         return path
  226.     i = 1
  227.     n = len(path)
  228.     while i < n and path[i] not in '/\\':
  229.         i = i + 1
  230.         continue
  231.         path[:1] != '~'
  232.     if 'HOME' in os.environ:
  233.         userhome = os.environ['HOME']
  234.     elif 'USERPROFILE' in os.environ:
  235.         userhome = os.environ['USERPROFILE']
  236.     elif 'HOMEPATH' not in os.environ:
  237.         return path
  238.     
  239.     try:
  240.         drive = os.environ['HOMEDRIVE']
  241.     except KeyError:
  242.         drive = ''
  243.  
  244.     userhome = join(drive, os.environ['HOMEPATH'])
  245.     if i != 1:
  246.         userhome = join(dirname(userhome), path[1:i])
  247.     
  248.     return userhome + path[i:]
  249.  
  250.  
  251. def expandvars(path):
  252.     '''Expand shell variables of the forms $var, ${var} and %var%.
  253.  
  254.     Unknown variables are left unchanged.'''
  255.     if '$' not in path and '%' not in path:
  256.         return path
  257.     import string as string
  258.     varchars = string.ascii_letters + string.digits + '_-'
  259.     res = ''
  260.     index = 0
  261.     pathlen = len(path)
  262.     while index < pathlen:
  263.         c = path[index]
  264.         if c == "'":
  265.             path = path[index + 1:]
  266.             pathlen = len(path)
  267.             
  268.             try:
  269.                 index = path.index("'")
  270.                 res = res + "'" + path[:index + 1]
  271.             except ValueError:
  272.                 '%' not in path
  273.                 '%' not in path
  274.                 res = res + path
  275.                 index = pathlen - 1
  276.             except:
  277.                 '%' not in path<EXCEPTION MATCH>ValueError
  278.             
  279.  
  280.         '%' not in path
  281.         if c == '%':
  282.             if path[index + 1:index + 2] == '%':
  283.                 res = res + c
  284.                 index = index + 1
  285.             else:
  286.                 path = path[index + 1:]
  287.                 pathlen = len(path)
  288.                 
  289.                 try:
  290.                     index = path.index('%')
  291.                 except ValueError:
  292.                     '%' not in path
  293.                     '%' not in path
  294.                     res = res + '%' + path
  295.                     index = pathlen - 1
  296.                 except:
  297.                     '%' not in path
  298.  
  299.                 var = path[:index]
  300.                 if var in os.environ:
  301.                     res = res + os.environ[var]
  302.                 else:
  303.                     res = res + '%' + var + '%'
  304.         elif c == '$':
  305.             '%' not in path if path[index + 1:index + 2] == '$' else '%' not in path<EXCEPTION MATCH>ValueError
  306.             var = ''
  307.             index = index + 1
  308.             c = path[index:index + 1]
  309.             while c != '' and c in varchars:
  310.                 var = var + c
  311.                 index = index + 1
  312.                 c = path[index:index + 1]
  313.                 continue
  314.                 '%' not in path
  315.             if var in os.environ:
  316.                 res = res + os.environ[var]
  317.             else:
  318.                 res = res + '$' + var
  319.             if c != '':
  320.                 index = index - 1
  321.             
  322.         else:
  323.             res = res + c
  324.         index = index + 1
  325.     return res
  326.  
  327.  
  328. def normpath(path):
  329.     '''Normalize path, eliminating double slashes, etc.'''
  330.     path = path.replace('/', '\\')
  331.     (prefix, path) = splitdrive(path)
  332.     if prefix == '':
  333.         while path[:1] == '\\':
  334.             prefix = prefix + '\\'
  335.             path = path[1:]
  336.     elif path.startswith('\\'):
  337.         prefix = prefix + '\\'
  338.         path = path.lstrip('\\')
  339.     
  340.     comps = path.split('\\')
  341.     i = 0
  342.     while i < len(comps):
  343.         None if comps[i] in ('.', '') else prefix.endswith('\\')
  344.         i += 1
  345.     if not prefix and not comps:
  346.         comps.append('.')
  347.     
  348.     return prefix + '\\'.join(comps)
  349.  
  350.  
  351. try:
  352.     from nt import _getfullpathname
  353. except ImportError:
  354.     
  355.     def abspath(path):
  356.         '''Return the absolute version of a path.'''
  357.         if not isabs(path):
  358.             path = join(os.getcwd(), path)
  359.         
  360.         return normpath(path)
  361.  
  362.  
  363.  
  364. def abspath(path):
  365.     '''Return the absolute version of a path.'''
  366.     if path:
  367.         
  368.         try:
  369.             path = _getfullpathname(path)
  370.         except WindowsError:
  371.             pass
  372.         except:
  373.             None<EXCEPTION MATCH>WindowsError
  374.         
  375.  
  376.     None<EXCEPTION MATCH>WindowsError
  377.     path = os.getcwd()
  378.     return normpath(path)
  379.  
  380. realpath = abspath
  381. if hasattr(sys, 'getwindowsversion'):
  382.     pass
  383. supports_unicode_filenames = sys.getwindowsversion()[3] >= 2
  384.  
  385. def relpath(path, start = curdir):
  386.     '''Return a relative version of a path'''
  387.     if not path:
  388.         raise ValueError('no path specified')
  389.     path
  390.     start_list = abspath(start).split(sep)
  391.     path_list = abspath(path).split(sep)
  392.     if start_list[0].lower() != path_list[0].lower():
  393.         (unc_path, rest) = splitunc(path)
  394.         (unc_start, rest) = splitunc(start)
  395.         if bool(unc_path) ^ bool(unc_start):
  396.             raise ValueError('Cannot mix UNC and non-UNC paths (%s and %s)' % (path, start))
  397.         bool(unc_path) ^ bool(unc_start)
  398.         raise ValueError('path is on drive %s, start on drive %s' % (path_list[0], start_list[0]))
  399.     start_list[0].lower() != path_list[0].lower()
  400.     for i in range(min(len(start_list), len(path_list))):
  401.         if start_list[i].lower() != path_list[i].lower():
  402.             break
  403.             continue
  404.     else:
  405.         i += 1
  406.     rel_list = [
  407.         pardir] * (len(start_list) - i) + path_list[i:]
  408.     if not rel_list:
  409.         return curdir
  410.     return join(*rel_list)
  411.  
  412.